/* Replication Script for "See G.I. Jane Run: The rise of female military veteran candidates for Congress" */
/* American Politics Research 2023 */
/* Theresa Schroeder Hageman, Rebecca Best, & Jeremy Teigen */
/* Contact Author is Rebecca Best: bestrh@umkc.edu */

/* Stata ADO file assumed to be installed: 

[2] package fre from http://fmwww.bc.edu/RePEc/bocode/f
      'FRE': module to display one-way frequency table by Ben Jann
	  
*/

local path "E:\Dropbox\replicate_gijane\" /*Your filepath | folder name goes here*/
clear 
cd `path'
use pooled_house_data_gijane.dta

/* Table 1 and its associated text summarizing data*/

#delimit ;
capture noisily drop considered ;
reg demshare i.year cook gopincumb demincumb dvet dmale rvet rmale south blanket, robust; 
gen considered = 1 if e(sample) ;
#delimit ;

tab rvet if rmale==0 & considered==1 ;
tab dvet if dmale==0 & considered==1 ;
tab rvet if rmale==1 & considered==1 ;
tab dvet if dmale==1 & considered==1 ;
fre rvet if considered==1 ;
fre dvet if considered==1 ;

tab rvet rmale if considered==1, col;
tab dvet dmale if considered==1, col;

sort year ;
by year: table rmale rvet if considered==1;
by year: table dmale dvet if considered==1;

/* Table 2 */
#delimit ;

ttest demshare if dmale==1 & considered==1, by(dvet);
ttest demshare if dmale==0 & considered==1, by(dvet);

tab gopincumb demincumb if considered==1 , cell;

/* Table 3 */
#delimit ;
sum cook demshare if considered==1 & dmale==1 & dvet==0 ;
sum cook demshare if considered==1 & dmale==1 & dvet==1 ;
sum cook demshare if considered==1 & dmale==0 & dvet==0 ;
sum cook demshare if considered==1 & dmale==0 & dvet==1 ;
sum cook gopshare if considered==1 & rmale==1 & rvet==0 ;
sum cook gopshare if considered==1 & rmale==1 & rvet==1 ;
sum cook gopshare if considered==1 & rmale==0 & rvet==0 ;
sum cook gopshare if considered==1 & rmale==0 & rvet==1 ;

/* Table 4 */
#delimit ;

reg demprop dvet dmale rvet rmale cook gopincumb demincumb south blanket i.year if considered==1, robust;
reg demprop dvet dmale rvet rmale cook gopincumb demincumb south blanket if year==2012 & considered==1 , robust;
reg demprop dvet dmale rvet rmale cook gopincumb demincumb south blanket if year==2014 & considered==1, robust;
reg demprop dvet dmale rvet rmale cook gopincumb demincumb south blanket if year==2016 & considered==1, robust;
reg demprop dvet dmale rvet rmale cook gopincumb demincumb south blanket if year==2018 & considered==1, robust;
reg demprop dvet dmale rvet rmale cook gopincumb demincumb south blanket if year==2020 & considered==1, robust;
reg demprop dvet##dmale rvet rmale cook gopincumb demincumb south blanket i.year if considered==1, robust;
reg demprop dvet##dmale rvet rmale cook gopincumb demincumb south blanket if year==2012 & considered==1, robust;
reg demprop dvet##dmale rvet rmale cook gopincumb demincumb south blanket if year==2014 & considered==1, robust;
reg demprop dvet##dmale rvet rmale cook gopincumb demincumb south blanket if year==2016 & considered==1, robust;
reg demprop dvet##dmale rvet rmale cook gopincumb demincumb south blanket if year==2018 & considered==1, robust;
reg demprop dvet##dmale rvet rmale cook gopincumb demincumb south blanket if year==2020 & considered==1, robust;
reg gopprop dvet dmale rvet##rmale cook gopincumb demincumb south blanket i.year if considered==1, robust;


/* Figure 1 Dem voteshare for female Dem vets per year with counts */
#delimit ;
capture noisily drop q* ;
table year if dvet==1 & dmale==0, c(mean demprop n demprop);

gen qyear = 2012 in 1;
replace qyear = 2014 in 2 ;
replace qyear = 2016 in 3 ;
replace qyear = 2018 in 4 ;
replace qyear = 2020 in 5 ;
label variable qyear "Year" ;
gen qdemprop = .4284 in 1 ;
replace qdemprop = .4400 in 2 ;
replace qdemprop = .4368 in 3;
replace qdemprop = .4931 in 4;
replace qdemprop = .4115 in 5 ;
label variable qdemprop "Mean Proportion Dem Vote Share, Female Dem Vets";
gen qdemfemvetcount = 7 in 1 ;
replace qdemfemvetcount = 6 in 2 ;
replace qdemfemvetcount = 4 in 3 ;
replace qdemfemvetcount = 10 in 4 ;
replace qdemfemvetcount = 14 in 5 ;

#delimit ;
twoway (
		connected qdemprop qyear 
		[aweight = qdemfemvetcount ]
		,
		msymbol(none)
		mlabel(qdemfemvetcount)
		mlabposition(6)
		mlabsize(vsmall)
		mlabgap(minuscule)
		yscale(range(.40 .56))
		ylabel(.40(.02).56,angle(horiz)  format(%3.2f))
		xscale(range(2011 2021))
		legend(off)
	)
	(scatter qdemprop qyear [aweight=qdemfemvetcount]
		,msymbol(circle_hollow)
		msize(huge)
	), scheme(s1mono)

	;

graph export figure1.png, as(png) replace ;
drop q* ;

/*Making 2018 Party Comparisons: Figure 2 for zooming in on 2018*/
#delimit ;	
reg demprop cook gopincumb demincumb i.south dvet##dmale rvet rmale blanket if year==2018 & considered==1 , robust; 
margins , over(dvet dmale) level(95) ;
marginsplot , 
	recast(connected)
	recastci(rcap)
	plot1opts(lpattern(dash) msymbol(none) )
	ci1opts(lpattern(dash) lcolor(%75))
	plot2opts(lpattern(solid) msymbol(none) )
	ci2opts(lpattern(solid) lcolor(%75))
	ytitle("Predicted Dem. Voteshare")
	ylabel(,angle(horiz))
	ylabel(.40(.02).56, format(%3.2f))
	xtitle(" ")
	xlabel(0 "Nonveteran" 1 "Veteran")
	xscale(range(-0.4 1.4))
	title("Democrats", size(medium))
	legend(off)
	text(.545 -0.2 "Men")
	text(.515 -0.25 "Women")
	scheme(s1mono)
;
graph save Graph dem_pane.gph , replace ;

#delimit ;	

reg gopprop cook gopincumb demincumb i.south dvet dmale rvet##rmale blanket if year==2018 ,  robust; 

margins , over(rvet rmale) level(95) ;
marginsplot , 
	recast(connected)
	recastci(rcap)
	ciopts(lwidth(vthin))
	plot1opts(lpattern(dash) msymbol(none) )
	ci1opts(lpattern(dash))
	plot2opts(lpattern(solid) msymbol(none) )
	ci2opts(lpattern(solid) )
	ytitle(Predicted GOP Voteshare)
	ylabel(,angle(horiz))
	ylabel(.40(.02).56, format(%3.2f))
	xtitle(" ")
	xlabel(0 "Nonveteran" 1 "Veteran")
	xscale(range(-0.4 1.4))
	title("Republicans", size(medium))
	legend(off)
	text(.490 1.20 "Men" )
	text(.405 1.25 "Women")
	scheme(s1mono)
;
graph save Graph gop_pane.gph , replace ;

#delimit ;
graph combine 
	dem_pane.gph 
	gop_pane.gph, 
	ycommon 
	scheme(s1mono)
	note("Post-estimation probabilities from model 11 from Table 4 with 95% confidence Intervals," "controlling for district partisanship, incumbency, blanket primaries, and the South." , size(vsmall))
;
graph export figure2.png, as(png) replace ; 
